<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<link rel="icon" type="image/png" href="img/favicon.ico">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>指纹单元</title>
		<link rel="stylesheet" href="css/style.min.css" />
	</head>

	<body>

		<header id="header" class="header">
			<div class="logo">
				<img src="img/logo.png" alt="logo" style="height: 62px;">
			</div>
			<div class="nav">
				<ul class="header-list">
					<li>
						<a href="index.html">指纹库</a>
					</li>
					<li>
						<a href="config.html">系统设置</a>
					</li>
					<li>
						<a class="active" href="#">指纹录入</a>
					</li>
				</ul>
			</div>
		</header>
		<div class="content">
			<fieldset>
				<legend>员工信息</legend>
				<table cellpadding="0" cellspacing="0">
					<tbody>
						<input id="ser" type="hidden"  value="" />
						
						<tr>
							<td width="35%" align="right">工号：</td>
							<td style="padding: 0;">
								<input id="code" class="inputxt" type="text" disabled="disabled" value="" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">姓名：</td>
							<td style="padding: 0;">
								<input id="name" class="inputxt" type="text" disabled="disabled" value="" />
							</td>
						</tr>
						<tr>
							<td width="35%" align="right">性别：</td>
							<td style="padding: 0;">
								<input id="sex" class="inputxt" type="text" disabled="disabled" value="" />
							</td>
						</tr>
					</tbody>
				</table>
			</fieldset>
			<button id="collectBt" type="button" class="btn btn-success btn-block" onclick="javascript:collectFinger();">点击开始采集</button>

			<div id="listemp">

			</div>
		</div>
	</body>
	
	<script type="text/javascript" src="js/app.min.js"></script>
	<script type="application/javascript">
		function collectFinger() {
			var empbody = document.getElementById('collectBt');
			var comm;
			var code = document.getElementById('code').value;
			var ser = document.getElementById('ser').value;
			if (empbody.textContent == "点击开始采集")
			{
				comm = 'first';
			}
			else
			{
				comm = 'second';
			}		
			ajax({
				url: 'collectFinger.cgi',
				data: {
					code: code,
					comm: comm,
					ser: ser
				},
				method: 'POST',
				success: function(rsp) {
					var obj = JSON.parse(rsp);
					if (obj.res == '1') {
						empbody = document.getElementById('listemp');
						var html = "";
						html += "<div class='alert alert-success'><strong>消息提示：</strong> 第一次采集成功！请拿开手指，再次放上。</div>";
						empbody.innerHTML = html;
						empbody = document.getElementById('collectBt');
						empbody.textContent = "再次采集";
					}
					if (obj.res == '2') {
						empbody = document.getElementById('listemp');
						var html = "";
						html += "<div class='alert alert-danger'><strong>采集失败：</strong> 手指重复录入，请更换手指！</div>";
						empbody.innerHTML = html;
						empbody = document.getElementById('collectBt');
						empbody.textContent = "点击开始采集";
						setTimeout(function(){empbody = document.getElementById('listemp');empbody.innerHTML = " ";},1000);
					}
					if (obj.res == '3') {
						empbody = document.getElementById('listemp');
						var html = "";
						html += "<div class='alert alert-danger'><strong>采集失败：</strong> 两次指纹不一致！</div>";
						empbody.innerHTML = html;
						empbody = document.getElementById('collectBt');
						empbody.textContent = "点击开始采集";
						setTimeout(function(){empbody = document.getElementById('listemp');empbody.innerHTML = " ";},1000);
					}
					if (obj.res == '4') {
						empbody = document.getElementById('listemp');
						var html = "";
						html += "<div class='alert alert-danger'><strong>采集失败：</strong> 手指中途未抬起！</div>";
						empbody.innerHTML = html;
						setTimeout(function(){empbody = document.getElementById('listemp');empbody.innerHTML = " ";},1000);
					}
					else if (obj.res == '0')
					{
						empbody = document.getElementById('listemp');
						var html = "";
						html += "<div class='alert alert-success'><strong>消息提示：</strong> 采集完成。</div>";
						empbody.innerHTML = html;
						setTimeout(function(){window.location.href='index.html';},1000);
					}
				},
				error: function(rsp) {
					console.log(rsp);
				}
			})
		}
		window.onload = function() {
			ajax({
				url: 'collectOL.cgi',
				data: {
					method: 'collect Onload'
				},
				method: 'POST',
				success: function(rsp) {
					var obj = JSON.parse(rsp);
					console.log(rsp);
					document.getElementById("code").value=obj.code;
					document.getElementById("name").value=obj.name;
					if (obj.sex == '1') 
					{
						document.getElementById("sex").value = "男";
					} else {
						document.getElementById("sex").value = "女";
					}
					document.getElementById("ser").value=obj.ser;
				},
				error: function(rsp) {
					console.log(rsp);
				}
			});
		}
	</script>
</html>